import { Auth } from '../auth';
//存储登录用户的信息
const user = {
    namespaced: true,
    state: {
        userInfo: Auth.getUserInfo() || {},
        //this.$store.state.user.user 获取user对象
        course: Auth.getCourse(),
        //this.$store.state.user.course 获取course对象
        // workId: Auth.getWorkId(),
        // //this.$store.state.user.workId 获取workId
        // courseId: Auth.getCourseId(),
        // refresh: true
    },
    getters: {
        user: state => state.user,
        course: state => state.course,
        workId: state => state.workId,
        courseId: state => state.courseId,
    },
    mutations: {
        CHANGE_REFRESH(state) {
            state.refresh = true
        },
        CHANGE_REFRESH2(state) {
            state.refresh = false
        },
        USER_INFO(state, info) {
            state.user = info;
            Auth.setUser(info);
        },
        COURSE_INFO(state, info) {
            state.course = info
            Auth.setCourse(info);
        },
        WORKID_INFO(state, info) {
            state.workId = info
            Auth.setWorkId(info);
        },
        COURSEID_INFO(state, info) {
            state.courseId = info
            Auth.setCourseId(info);
        },
        LOGOUT(state) {
            state.user = {}
            state.course = {}
            state.workId = {}
            state.courseId = {}
            Auth.removeUser();
            Auth.removeCourse();
            Auth.removeWorkId();
            Auth.removeCourseId();
        }
    },
    actions: {
        saveUserInfo({ commit }, user) {
            commit('USER_INFO', user);
        },
        saveCourseInfo({ commit }, course) {
            commit('COURSE_INFO', course)
        },
        saveWorkIdInfo({ commit }, workId) {
            commit('WORKID_INFO', workId)
        },
        saveCourseIdInfo({ commit }, courseId) {
            commit('COURSEID_INFO', courseId)
        },
        logout({ commit }) {
            commit('LOGOUT');
        }
    },
};
export default user;

